{extend name='main'}

{block name="button"}
{if auth("add")}
<button data-open='{:url("add")}' data-title="添加" class='layui-btn layui-btn-sm layui-btn-primary'>添加</button>
{/if}
{/block}


{block name="content"}
<div class="think-box-shadow">
    <form action="{:sysuri()}" method="post" data-auto="true" class="layui-form layui-card" data-table-id="UserTable">
        <div class="layui-card-body padding-left-40">
            <div class="layui-row layui-col-space10">
                <div class="layui-col-xs12">
                    <div class="layui-form-item margin-bottom-5">
                        <div class="help-label"><b>图片</b>Images</div>
                        <div class="layui-textarea help-images">
                            <input type="hidden" value="{$vo.pic|default=''}" name="pic">
                        </div>
                        <script>$('[name=pic]').uploadMultipleImage();</script>
                    </div>
                </div>
                <div class="layui-col-xs9">
                    <div class="layui-form-item">
                        <label class="relative block">
                            <span class="color-green font-w7">标题</span>
                            <span class="color-desc margin-left-5">Title</span>
                            <input type="text" name="title" value='{$vo.title|default=""}' required placeholder="请输入标题" class="layui-input">
                        </label>
                    </div>
                </div>
                <div class="layui-col-xs3">
                    <div class="layui-form-item">
                        <div class="relative block">
                            <span class="color-green font-w7">状态</span>
                            <div class="layui-input help-checks">
                                {foreach
                                [['title'=>'是','value'=>1,'is_default'=>1],['title'=>'否','value'=>0,'is_default'=>0]]  as $v }
                                {if isset($vo.status) && $vo.status==$v.value || !isset($vo.status) && $v.is_default==1 }
                                <input type="radio" name="status" checked title="{$v.title}" value="{$v.value}">
                                {else /}<input type="radio" name="status" title="{$v.title}" value="{$v.value}">
                                {/if}
                                {/foreach}
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs3">
                    <div class="layui-form-item">
                        <label class="relative block">
                            <span class="color-green font-w7">类型</span>
                            <span class="color-desc margin-left-5"></span>
                            <select class="layui-select" name="cate_id" required>
                                <option value="">请选择</option>
                                {notempty name='cate'}
                                {foreach $cate as $k=>$v}
                                {if isset($vo.cate_id) and $vo.cate_id eq $v.id}
                                <option selected value="{$v.id}">{$v.name}</option>
                                {else}
                                <option  value="{$v.id}">{$v.name}</option>
                                {/if}{/foreach}
                                {/notempty}
                            </select>
                        </label>
                    </div>
                </div>
                <div class="layui-col-xs3">
                    <div class="layui-form-item">
                        <label class="relative block">
                            <span class="color-green font-w7">地区</span>
                            <span class="color-desc margin-left-5"></span>
                            <select class="layui-select" name="region_id" required>
                                <option value="">请选择</option>
                                {notempty name='region'}
                                {foreach $region as $k=>$v}
                                {if isset($vo.region_id) and $vo.region_id eq $v.id}
                                <option selected value="{$v.id}">{$v.name}</option>
                                {else}
                                <option  value="{$v.id}">{$v.name}</option>
                                {/if}{/foreach}
                                {/notempty}
                            </select>
                        </label>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="relative block">
                            <span class="color-green font-w7">地址</span>
                            <span class="color-desc margin-left-5">Address</span>
                            <input type="text" name="address" value='{$vo.address|default=""}' required placeholder="请输入地址" class="layui-input">
                        </label>
                    </div>
                </div>
                <div class="layui-col-xs3">
                    <div class="layui-form-item">
                        <label class="relative block">
                            <span class="color-green font-w7">手机-国内</span>
                            <span class="color-desc margin-left-5">Mobile China</span>
                            <input type="text" name="mobile_cn" lay-verify="required|phone" value='{$vo.mobile_cn|default=""}' required placeholder="请输入国内手机" class="layui-input">
                        </label>
                    </div>
                </div>
                <div class="layui-col-xs3">
                    <div class="layui-form-item">
                        <label class="relative block">
                            <span class="color-green font-w7">手机-印尼</span>
                            <span class="color-desc margin-left-5">Mobile Indonesia</span>
                            <input type="text" name="mobile_ind" value='{$vo.mobile_ind|default=""}' required placeholder="请输入国内手机" class="layui-input">
                        </label>
                    </div>
                </div>
                <div class="layui-col-xs3">
                    <div class="layui-form-item">
                        <label class="relative block">
                            <span class="color-green font-w7">日期时间</span>
                            <span class="color-desc margin-left-5">DateTime</span>
                            <input type="text" data-date-time-range name="wechat" value='{$vo.wechat|default=""}' required placeholder="请输入微信" class="layui-input">
                        </label>
                    </div>
                </div>
                <div class="layui-col-xs3">
                    <div class="layui-form-item">
                        <label class="relative block">
                            <span class="color-green font-w7">邮箱</span>
                            <span class="color-desc margin-left-5">Email</span>
                            <input type="text" name="email" lay-verify="email" value='{$vo.email|default=""}' required placeholder="请输入邮箱" class="layui-input">
                        </label>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <div class="help-label"><b>正文</b>Content</div>
                <label class="relative block">
                    <textarea name="content" required class="layui-textarea">{$vo.content|default=''|raw}</textarea>
                </label>
                <div class="help-block">内容，建议控制4000字以内</div>
                <script>
                    require(['ckeditor', 'angular'], function () {
                        window.createEditor('[name="content"]', {height: 500});
                    })
                </script>
            </div>

        </div>
        <div class="hr-line-dashed"></div>
        {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}
        <div class="layui-form-item text-center">
            <button class="layui-btn" type='submit' lay-submit lay-filter="save-data">保存数据</button>
            <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-close>
                取消编辑
            </button>
        </div>
    </form>
</div>

<script>
    layui.use(['form'], function(){
        const layer = layui.layer;
        const $ = layui.jquery
            , upload = layui.upload;
        // 提交事件
        form.on('submit(save-data)', function(data){
            var field = data.field; // 获取表单字段值
            console.log('field',field);
            if (field.content==='' || field.content==='<p><br></p>') {
                layer.alert('内容不能为空');
                return false;
            }
            if (!field.pic) {
                $.msg.error('请上传图片');
                return false;
            }
            return true; // 阻止默认 form 跳转
        });





        // 普通事件
        // util.on('lay-on', {
            // 获取验证码
            // "get-vercode": function(othis){
            //     var isvalid = form.validate('.demo-phone'); // 主动触发验证，v2.7.0 新增
            //     // 验证通过
            //     if(isvalid){
            //         layer.msg('手机号规则验证通过');
            //         // 此处可继续书写「发送验证码」等后续逻辑
            //         // …
            //     }
            // }
        //});

    });
</script>

{/block}

